package cate.game.role.res.guild.msg;

import cate.game.GameBody;
import cate.game.client.ClientContext;
import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.MsgInput;
import cate.game.client.msg.id.MsgIdGuild;
import cate.game.role.Role;
import cate.game.role.res.guild.po.basic.GuildBasicPO;
import cate.game.role.res.guild.po.GuildPO;
import easy.java.dev.note.NoteField;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

@ClientMsg(title = "公会列表的请求")
public class GuildListReq implements MsgInput {
    @NoteField(value = "公会名称描述")
    public String des;

    @Override
    public MsgConfig conf() {
        return MsgIdGuild.GUILD_LIST_REQ;
    }

    @Override
    public void execute(GameBody game, ClientContext cc) {
        Role role = cc.getRole();
        List<GuildBasicPO> list = new ArrayList<>();
        if (StringUtils.isBlank(des)) {
            for (GuildPO guildPO : game.res.guild.getGuildList()) {
                list.add(guildPO.basic);
            }
            role.sendNow(new GuildListResp(list,des));
        } else {
            for (GuildPO guildPO : game.res.guild.getGuildList()) {
                //名字模糊匹配，编号精确匹配
                if (guildPO.uid.equals(des) || guildPO.basic.guildName.contains(des)) {
                    list.add(guildPO.basic);
                }
            }
            if (list.isEmpty())
                game.notice.message(role,"未找到该公会");
            role.sendNow(new GuildListResp(list,des));
        }
    }
}
